package com.mrd.serverconnect.pkg;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * Created by liushenen on 2018/1/31.
 */

public class HeartPKGHelp extends PKGBase {
    private static final String TAG = "ModBus";
    public HeartReqData readReqData(byte[] head, byte funCode, DataInputStream dataInputStream) {
        HeartPKGHelp.HeartReqData mAuthReqData = new HeartPKGHelp.HeartReqData();
        try {
            byte[] sn = new byte[16];
            int version = dataInputStream.readInt();
            dataInputStream.read(sn);
            mAuthReqData.head = head;
            mAuthReqData.funCode = funCode;
            mAuthReqData.sn = sn;
            mAuthReqData.version = version;
//            Log.i(TAG, "心跳请求 =================");
////            Log.i(TAG, "设备版本：" + version);
////            Log.i(TAG, "设备号:" + new String(sn, 0,13,"utf-8"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return mAuthReqData;
    }

    public void sendData(byte[] head, OutputStream outputStream) {
        try {
            head[5] = 0x3;
            outputStream.write(head);
            outputStream.write(0x43);
            outputStream.write(0x00);
            outputStream.flush();
            //Log.i(TAG, "心跳回应 =================");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    public class HeartReqData extends BaseReqData {
        public  int version; //版本号
        public byte[] sn;//sn号
    }

}
